package engine.newUi
{
	import flash.events.MouseEvent;
	import newx.com.control.button.NxButton;
	import engine.net.mgr.SystemSender;
	import newx.com.control.window.NxWindowEvent;

	/**
	 *GMCC服务类型逻辑 
	 * @author liuel
	 * 
	 */	
	public class GmccFunctionLogic
	{
		private static var _self:GmccFunctionLogic
		private var _ui	:GmccFunctionUI;
		
		private var _questionArr:Array=[];
		public static function getInstance():GmccFunctionLogic
		{
			if(_self ==null)
			{
				_self = new GmccFunctionLogic();
			}
			return _self;
		}
		public function GmccFunctionLogic()
		{
			_ui = GmccFunctionUI.getInstance();
		}
		public function  Init():void
		{
		}
		public function	BeforeShow():void
		{
			setBttonName();
			addEventListener();
		}
		public function	AfterHide():void
		{
			removeEventListener();
		}
		private function addEventListener():void
		{
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClose);
			_ui.closebtn.addEventListener(MouseEvent.CLICK,onCloseHandle);	
			_ui.btn1.addEventListener(MouseEvent.CLICK,onClickHandle);	
			_ui.btn2.addEventListener(MouseEvent.CLICK,onClickHandle);	
			_ui.btn3.addEventListener(MouseEvent.CLICK,onClickHandle);	
			_ui.btn4.addEventListener(MouseEvent.CLICK,onClickHandle);	
			
		}
		private function removeEventListener():void
		{
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClose);
			_ui.closebtn.removeEventListener(MouseEvent.CLICK,onCloseHandle);	
			_ui.btn1.removeEventListener(MouseEvent.CLICK,onClickHandle);	
			_ui.btn2.removeEventListener(MouseEvent.CLICK,onClickHandle);	
			_ui.btn3.removeEventListener(MouseEvent.CLICK,onClickHandle);	
			_ui.btn4.removeEventListener(MouseEvent.CLICK,onClickHandle);	
		}
		private function onClose(e:NxWindowEvent):void
		{
			_ui.hide();
		}
		private function onCloseHandle(e:MouseEvent):void
		{
			_ui.hide();
		}
		private function onClickHandle(e:MouseEvent):void
		{
			var constr:String="";
			constr=(e.target as NxButton).label;
			send(constr);
			_ui.hide();
		}
		/**
		 *发送GM帮助的类型 
		 * @param str
		 * 
		 */		
		private function send(str:String):void
		{
			SystemSender.getInstance().SendGMCCTOServer("#EXTE#con#"+str);
			GmccLogic.getInstance().gmccUi.showOrHide();
			GmccLogic.getInstance().gmHelpState=true;
		}
		/**
		 *设置可选帮助的名称 
		 * 
		 */		
		private function setBttonName():void
		{
			for(var i:String in _questionArr)
			{
				if(int(i)<4)
				{
					if(_questionArr[int(i)] =="")
					{
						(_ui["btn"+(int(i)+1)] as NxButton).visible =false;
					}
					else 
					{
						(_ui["btn"+(int(i)+1)] as NxButton).label =_questionArr[int(i)];
					}
					
				}
			}
		}
		/**
		 *设置可帮助选项 
		 * @param arr
		 * 
		 */		
		public function set questionName(arr:Array):void
		{
			_questionArr=[];
			_questionArr =arr;
			_ui.showOrHide();
			
		}
	}
}